package com.lc.service.serviceImpl;

import com.lc.dao.MyBatisDao;
import com.lc.service.ITestService;
import com.lc.service.ITestServiceProvider;
import com.lc.utils.MyApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lichao on 2017/5/5.
 */
@Service(value = "ITestService.default")
public class TestServiceImpl implements ITestService {

    @Resource
    private MyBatisDao<Object> myBatisDao;

    @Resource
    private ITestServiceProvider testService;

    @Resource(name = "redisTemplate")
    private StringRedisTemplate redisTemplate;

    @Override
    public List getData(Integer id) {
        List list = null;
        try {
            list = myBatisDao.getByList("testUser.selectData", id);
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public List getRedisData(String key) {
        List list = null;
        try {
            list = new ArrayList();
            list.add(redisTemplate.opsForValue().get(key));

        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public String getProviderData(String id) {
        testService = (ITestServiceProvider)MyApplicationContext.getBean("testService");
        return testService.TestMethod(id);
    }

    @PostConstruct
    public void init(){
        System.out.println("______________service_______________");
    }

    public void run(){
        System.out.println("run方法");
    }
}
